package h0721;

import java.util.*;

/**
  * @description 冷热内存标记
  * @author 不知名帅哥
  * @date 2024/7/21 21:34
  * @version 1.0
*/
public class MarkHotColdRam {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i]=sc.nextInt();
        }
        int limit = sc.nextInt(); //阈值
        List<int[]> result = getResult(arr, limit);
        System.out.println(result.size());
        if (!result.isEmpty()){
            for (int[] a : result) {
                System.out.println(a[0]);  //按照内存访问频次降序输出内存页框号
            }
        }
    }

    private static List<int[]> getResult(int[] arr, int limit) {
        Map<Integer,Integer> frequencies=new HashMap<>();//每页内存出现频次
        for (int a : arr) {
            frequencies.put(a, frequencies.getOrDefault(a,0)+1);
        }
        List<int[]> ans=new ArrayList<>();  //需要按照内存访问频次降序输出
        for (Integer a : frequencies.keySet()) {
            Integer value = frequencies.get(a);
            if (value>=limit){
                ans.add(new int[]{a,value});
            }
        }
        ans.sort((a, b) -> b[1] - a[1]); //排序，按照value降序
        return ans;
    }
}
